
%%% IMPORT ESTIMATED PARAMETERS FOR CONSUMPTION
estimated_parameters = importdata('NH_CES_estimated_parameters_refined.mat')';
sigma = estimated_parameters(1);
epsilon_a = estimated_parameters(2);
epsilon_m = estimated_parameters(3);
epsilon_s = estimated_parameters(4);
omega_a = estimated_parameters(5);
omega_m = estimated_parameters(6);
omega_s = estimated_parameters(7);

%%% TAKE THETAs FROM TOMBE ESTIMATES
theta_ag = 4.06;
theta_manu = 4.63;
theta_serv = 4;

n_varieties_ag = 20000;
n_varieties_manu = 20000;
n_varieties_serv = 20000;

country_names

% Use scaled productivity parameters so baseline GDP is unchanged
input_data
T_multiplier = importdata('temp_T_multiplier_lowtradecost_frictionless.mat');
ag_T_vec = data_ag_GDPpercap.*T_multiplier;
manu_T_vec = data_manu_GDPpercap.*T_multiplier;
serv_T_vec = data_serv_GDPpercap.*T_multiplier;

data_GDP_mat = repmat(data_GDP,n_countries,1);

% Apply tau = 1
% Trade Cost is for Importer Country (Column) from Exporter Country (Row)


ag_trade_cost_mat = ones(n_countries,n_countries);
manu_trade_cost_mat = ones(n_countries,n_countries);

ag_trade_cost_mat(logical(eye(size(ag_trade_cost_mat)))) = 1;
manu_trade_cost_mat(logical(eye(size(manu_trade_cost_mat)))) = 1;

ag_import_cost_3D = ones(n_varieties_ag,n_countries,n_countries);
manu_import_cost_3D = ones(n_varieties_ag,n_countries,n_countries);

for cc = 1:length(country)
ag_import_cost_vec.(country{cc}) = ag_trade_cost_mat(:,cc)';
ag_import_cost_country.(country{cc}) = repmat(ag_import_cost_vec.(country{cc}), n_varieties_ag, 1);
ag_import_cost_3D(:,:,cc) = ag_import_cost_country.(country{cc});
manu_import_cost_vec.(country{cc}) = manu_trade_cost_mat(:,cc)';
manu_import_cost_country.(country{cc}) = repmat(manu_import_cost_vec.(country{cc}), n_varieties_manu, 1);
manu_import_cost_3D(:,:,cc) = manu_import_cost_country.(country{cc});
end

% Find equilibrium 

sim_Frechets
P_a_vec = geomean(ag_consumed_prices_mat);
P_m_vec = geomean(manu_consumed_prices_mat);
P_s_vec = geomean(serv_consumed_prices_mat);

find_equilibrium_parallel_lowtradecost

sim_ag_shares_GDP = ag_income_vec./total_income_vec;
sim_manu_shares_GDP = manu_income_vec./total_income_vec;
sim_serv_shares_GDP = serv_income_vec./total_income_vec;






